figure.Pipe = new Class({
    Extends:figure.DomFigure,

    initialize: function(id, css) {
        this.parent(0, 0);
        this.id = id;
        css['background-color'] = figure.pipeColor;
        css['border-radius'] = '25px';
        this.myClass = id.replace(/[0-9]/g, '');
        this.createElement('div', {
            id: id,
            class: id.replace(/[0-9]/g, ''),
            css: css
        });
        this.element = this.getElement();
        this.prepareAnimation();
    },

    prepareAnimation: function() {
        var pipe = this.element;
        var myClass = this.myClass;
        var id = this.id;
        pipe.on('startSimulation',
            function loop(){
                var bomba = $('#' + id.replace('pipe', 'bomba'));
                if (id == 'pipeAfecho') {
                    figure.pipesStatus['pipeAfechoEnd'] = figure.pipesStatus['pipeFiltrEnd'];
                }
                var isOpen = figure.isOpen(myClass);
                if (!isOpen || figure.stopAnimation) {
                    window.setTimeout(function() { loop() }, figure.speed);
                    if (bomba.length > 0) {
                        bomba.trigger('apagarBomba');
                    }
                    return;
                } else if (isOpen) {
                    pipe.animate({'background-color': figure.waterColor}, 200)
                        .animate({'background-color': figure.pipeColor}, 200);
                    if (bomba.length > 0) {
                        bomba.trigger('prenderBomba');
                    }
                }
                window.setTimeout(function() { loop() }, figure.speed);
            });
    }


});